package com.yft.sys.modules.preCheck.controller;

import com.yft.sys.modules.preCheck.controller.base.BaseController;
import com.yft.sys.modules.preCheck.model.UserMaster;
import com.yft.sys.modules.preCheck.service.UserMasterService;
import com.yft.sys.utils.RedisUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lr
 */
@RestController
@RequestMapping("/test/user")
public class UserMasterController extends BaseController {

    @Autowired
    private UserMasterService userMasterService;
    @Autowired
    private RedisUtils redisUtils;

    @RequestMapping("/all")
    @RequiresPermissions("test:user:all")
    public Object getMasterList() {
        return getSuccessResult(userMasterService.getMasterList());
    }

    @RequestMapping("/save")
    //@RequiresPermissions("test:user:save")
    public Object save(UserMaster user) {
        userMasterService.save(user);
        return getSuccessResult();
    }

    @RequestMapping("/update")
    //@RequiresPermissions("test:user:update")
    public Object update(UserMaster user) {
        userMasterService.update(user);
        return getSuccessResult();
    }

    @RequestMapping("/remove")
    // @RequiresPermissions("test:user:remove")
    public Object remove(Long id) throws Exception {
        userMasterService.remove(id);
        return getSuccessResult();
    }

    @RequestMapping("/info/{userId}")
    // @RequiresPermissions("test:user:info")
    public Object findById(@PathVariable("userId") Long id) {
        redisUtils.set("userId", id);
        String value = redisUtils.get("userId");
        System.out.println(String.valueOf(value));

        return getSuccessResult(userMasterService.findById(id));
    }

}
